package org.jivesoftware.smack;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;

public class PacketCollector
{
  private static final int MAX_PACKETS = 65536;
  private boolean cancelled = false;
  private Connection conection;
  private PacketFilter packetFilter;
  private LinkedBlockingQueue<Packet> resultQueue;

  protected PacketCollector(Connection paramConnection, PacketFilter paramPacketFilter)
  {
    this.conection = paramConnection;
    this.packetFilter = paramPacketFilter;
    this.resultQueue = new LinkedBlockingQueue(65536);
  }

  public void cancel()
  {
    if (!(this.cancelled))
    {
      this.conection.removePacketCollector(this);
      this.cancelled = true;
    }
  }

  public PacketFilter getPacketFilter()
  {
    return this.packetFilter;
  }

  public Packet nextResult()
  {
    Packet localPacket;
    try
    {
      localPacket = (Packet)this.resultQueue.take();
      return localPacket;
    }
    catch (InterruptedException localInterruptedException)
    {
    }
  }

  public Packet nextResult(long paramLong)
  {
    Packet localPacket1;
    long l = paramLong + System.currentTimeMillis();
    try
    {
      Packet localPacket2 = (Packet)this.resultQueue.poll(paramLong, TimeUnit.MILLISECONDS);
      localPacket1 = localPacket2;
      return localPacket1;
    }
    catch (InterruptedException localInterruptedException)
    {
      if (System.currentTimeMillis() < l);
      localPacket1 = null;
    }
  }

  public Packet pollResult()
  {
    return ((Packet)this.resultQueue.poll());
  }

  /**
   * @deprecated
   */
  // ERROR //
  protected void processPacket(Packet paramPacket)
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: aload_1
    //   3: ifnonnull +6 -> 9
    //   6: aload_0
    //   7: monitorexit
    //   8: return
    //   9: aload_0
    //   10: getfield 27	org/jivesoftware/smack/PacketCollector:packetFilter	Lorg/jivesoftware/smack/filter/PacketFilter;
    //   13: ifnull +16 -> 29
    //   16: aload_0
    //   17: getfield 27	org/jivesoftware/smack/PacketCollector:packetFilter	Lorg/jivesoftware/smack/filter/PacketFilter;
    //   20: aload_1
    //   21: invokeinterface 81 2 0
    //   26: ifeq -20 -> 6
    //   29: aload_0
    //   30: getfield 34	org/jivesoftware/smack/PacketCollector:resultQueue	Ljava/util/concurrent/LinkedBlockingQueue;
    //   33: aload_1
    //   34: invokevirtual 85	java/util/concurrent/LinkedBlockingQueue:offer	(Ljava/lang/Object;)Z
    //   37: ifne -31 -> 6
    //   40: aload_0
    //   41: getfield 34	org/jivesoftware/smack/PacketCollector:resultQueue	Ljava/util/concurrent/LinkedBlockingQueue;
    //   44: invokevirtual 73	java/util/concurrent/LinkedBlockingQueue:poll	()Ljava/lang/Object;
    //   47: pop
    //   48: goto -19 -> 29
    //   51: astore_2
    //   52: aload_0
    //   53: monitorexit
    //   54: aload_2
    //   55: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   9	48	51	finally
  }
}